import request from '@/utils/request'

export function req(api, method = 'GET', params = {}, headers = {}) {
  if (method === 'GET' || method === 'get') {
    return get(api, params, headers)
  }
  if (method === 'POST' || method === 'post') {
    return post(api, params, headers)
  }
  if (method === 'PUT' || method === 'put') {
    return put(api, params, headers)
  }
  if (method === 'DELETE' || method === 'delete' || method === 'del') {
    return remove(api, params, headers)
  }
  if (method === 'PATCH' || method === 'patch') {
    return patch(api, params, headers)
  }
}

export function get(api, params = {}, headers = {}) {
  return request({
    url: api,
    method: 'GET',
    headers: headers,
    params: params
  })
}

export function post(api, params = {}, headers = {}) {
  return request({
    url: api,
    method: 'POST',
    headers: headers,
    data: params
  })
}

export function put(api, params = {}, headers = {}) {
  return request({
    url: api,
    method: 'PUT',
    headers: headers,
    data: params
  })
}

export function remove(api, params = {}, headers = {}) {
  return request({
    url: api,
    method: 'DELETE',
    headers: headers,
    data: params
  })
}

export function patch(api, params = {}, headers = {}) {
  return request({
    url: api,
    method: 'PATCH',
    headers: headers,
    data: params
  })
}
